<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>入职申请</title>
    <script src="../../../../../res/js/jquery-3.4.1.min.js" charset="utf-8"></script>
    <script src="../../../../../res/js/login_common.js" charset="utf-8"></script>
    <script src="../../../../../res/layui/layui.js" charset="utf-8"></script>
    <script src="../../../../../res/js/Tools.js" charset="utf-8"></script>
    <link rel="shortcut icon" type="image/x-icon" href="../../../../../res/images/favicon.ico">
    <link rel="stylesheet" href="../../../../../res/layui/css/layui.css" media="all">
    <style>
        #isHealthMaimLevel {
            display: none;
        }
    </style>

    <script>
        $.ajaxSetup({
            async: false
        });
    </script>
</head>
<body style="padding: 10px">
<div style="display: none" id="bodys">
    <form action="" class="layui-form layui-form-pane" lay-filter="example">
        <h1 align="center" style="margin-bottom: 20px">员工信息变更流程</h1>
        <input name="pkEntryId" id="pkEntryId" type="hidden"/>
        <input name="pkEntryAlterationId" id="pkEntryAlterationId" type="hidden"/>
        <input name="isRevision" id="isRevision" type="hidden"/>
        <div>
            <div class="layui-form-item layui-form-text">
                <div class="layui-input-block" id="oaEntryEducations">
                    <fieldset class="layui-elem-field">
                        <legend>
                            教育经历
                        </legend>
                        <div class="layui-field-box">
                            <table class="layui-table" id="oaEntryEducation"
                                   lay-filter="oaEntryEducation">
                            </table>
                        </div>
                    </fieldset>
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <div class="layui-input-block" id="oaEntryWorks">
                    <fieldset class="layui-elem-field">
                        <legend>
                            工作经历
                        </legend>
                        <div class="layui-field-box">
                            <table class="layui-table" id="oaEntryWork"
                                   lay-filter="oaEntryWork">

                            </table>
                        </div>
                    </fieldset>
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <div class="layui-input-block" id="oaEntryTrains">
                    <fieldset class="layui-elem-field">
                        <legend>
                            培训经历
                        </legend>
                        <div class="layui-field-box">
                            <table class="layui-table" id="oaEntryTrain"
                                   lay-filter="oaEntryTrain">
                            </table>
                        </div>
                    </fieldset>
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <div class="layui-input-block" id="oaEntryFamilys">
                    <fieldset class="layui-elem-field">
                        <legend>
                            家庭成员
                        </legend>
                        <div class="layui-field-box">
                            <table class="layui-table" id="oaEntryFamily"
                                   lay-filter="oaEntryFamily">
                            </table>
                        </div>
                    </fieldset>
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <div class="layui-input-block" id="oaEmergencyContacts">
                    <fieldset class="layui-elem-field">
                        <legend>
                            紧急联络人
                        </legend>
                        <div class="layui-field-box">
                            <table class="layui-table" id="oaEmergencyContact"
                                   lay-filter="oaEmergencyContact">

                            </table>
                        </div>
                    </fieldset>
                </div>
            </div>
        </div>

        <!-- 提交-->
        <div class="layui-form-item" id="sub">
            <div class="layui-input-block" id="flows">
                <button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1">通过</button>
                <input type="button" id="demo2" class="layui-btn layui-btn-primary" value="不通过">
            </div>

        </div>
    </form>

    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
        <legend>流程日志</legend>
    </fieldset>
    <ul class="layui-timeline" id="schedule">

    </ul>
</div>
<script>
    let pkEntryAlterationId = getQueryString("pkEntryAlterationId");
    let show = getQueryString("show");
    let oaEntryEducationTable; // 教育经历
    let oaEntryWorkTable; //工作经历
    let oaEntryTrainTable; //培训经历
    let oaEntryFamilyTable; // 家庭成员
    let oaEmergencyContactTable; // 紧急联络人
    layui.use(['form', 'laydate', 'table'], function () {
        var table = layui.table
            , form = layui.form
            , layer = layui.layer
            , laydate = layui.laydate;
            let datas = getAjaxById(getRootPath() + "OaEntryAlterationFlowAction/findById/"+pkEntryAlterationId);
            $("#pkEntryAlterationId").val(pkEntryAlterationId);
            let pkEntry = $("#pkEntryId");
            console.info(datas);
            pkEntry.val(datas.entryId);

            oaEntryEducationTable = table.render({
                elem: '#oaEntryEducation'
                , url: getRootPath() + 'oaEntryEducation/selectAlls?entryId=' + pkEntry.val()
                , headers: {token: token}
                , title: '教育经历'
                , parseData: function (res) {
                    if (res.code === 500) {
                        return false
                    }
                    return {
                        "code": res.data.code,
                        "msg": res.data.msg,
                        "count": res.data.count,
                        "data": res.data.data
                    };
                }
                , cols: [[
                    {type: 'numbers', title: '序列', fixed: 'left', width: 120}
                    , {
                        field: 'startTime', title: '开始时间', templet: function (row) {
                            if (row.startTime) {
                                return dateFormat("yyyy-MM-dd", new Date(row.startTime));
                            } else {
                                return "";
                            }
                        }, width: 120
                    }
                    , {
                        field: 'endTime', title: '结束时间', templet: function (row) {
                            if (row.endTime) {
                                return dateFormat("yyyy-MM-dd", new Date(row.endTime));
                            } else {
                                return "";
                            }
                        }, width: 120
                    }
                    , {field: 'educationSchool', title: '院校名称', width: 120}
                    , {field: 'educationDegreeName', title: '学历', width: 120}
                    , {field: 'educationMajor', title: '专业', width: 120}
                    , {field: 'educationSeries', title: '证书', width: 120}
                ]]
            });

            oaEntryWorkTable = table.render({
                elem: '#oaEntryWork'
                , url: getRootPath() + 'oaEntryWork/selectAlls?entryId=' + pkEntry.val()
                , headers: {token: token}
                , title: '工作经历'
                , parseData: function (res) {
                    if (res.code === 500) {
                        return false
                    }
                    return {
                        "code": res.data.code,
                        "msg": res.data.msg,
                        "count": res.data.count,
                        "data": res.data.data
                    };
                }
                , cols: [[
                    {type: 'numbers', title: '序列', fixed: 'left'}
                    , {
                        field: 'startTime', title: '开始时间', templet: function (row) {
                            if (row.startTime) {
                                return dateFormat("yyyy-MM-dd", new Date(row.startTime));
                            } else {
                                return "";
                            }
                        }
                    }
                    , {
                        field: 'endTime', title: '结束时间', templet: function (row) {
                            if (row.endTime) {
                                return dateFormat("yyyy-MM-dd", new Date(row.endTime));
                            } else {
                                return "";
                            }
                        }
                    }
                    , {field: 'workUnit', title: '工作单位'}
                    , {field: 'workPost', title: '职位'}
                    , {field: 'voucher', title: '证明人姓名'}
                    , {field: 'phone', title: '证明人电话'}
                    , {field: 'reasonsForLeaving', title: '离职原因'}
                ]]
            });

            oaEntryTrainTable = table.render({
                elem: '#oaEntryTrain'
                , url: getRootPath() + 'oaEntryTrain/selectAlls?entryId=' + pkEntry.val()
                , headers: {token: token}
                , title: '培训经历'
                , parseData: function (res) {
                    if (res.code === 500) {
                        return false
                    }
                    return {
                        "code": res.data.code,
                        "msg": res.data.msg,
                        "count": res.data.count,
                        "data": res.data.data
                    };
                }
                , cols: [[
                    {type: 'numbers', title: '序列', fixed: 'left'}
                    , {
                        field: 'startTime', title: '开始时间', templet: function (row) {
                            if (row.startTime) {
                                return dateFormat("yyyy-MM-dd", new Date(row.startTime));
                            } else {
                                return "";
                            }
                        }
                    }
                    , {
                        field: 'endTime', title: '结束时间', templet: function (row) {
                            if (row.endTime) {
                                return dateFormat("yyyy-MM-dd", new Date(row.endTime));
                            } else {
                                return "";
                            }
                        }
                    }
                    , {field: 'trainContent', title: '培训内容'}
                    , {field: 'trainInstitutional', title: '培训组织机构'}
                    , {field: 'trainResult', title: '培训结果'}
                ]]
            });

            oaEntryFamilyTable = table.render({
                elem: '#oaEntryFamily'
                , url: getRootPath() + 'oaEntryFamily/selectAlls?entryId=' + pkEntry.val()
                , headers: {token: token}
                , title: '家庭成员'
                , parseData: function (res) {
                    if (res.code === 500) {
                        return false
                    }
                    return {
                        "code": res.data.code,
                        "msg": res.data.msg,
                        "count": res.data.count,
                        "data": res.data.data
                    };
                }
                , cols: [[
                    {type: 'numbers', title: '序列', fixed: 'left'}
                    , {field: 'familyName', title: '姓名'}
                    , {field: 'relation', title: '关系'}
                    , {field: 'familyEmployer', title: '工作单位'}
                    , {field: 'post', title: '所在岗位及职务'}
                ]]
            });
            if(show){
                $("#sub").hide();
            }

            oaEmergencyContactTable = table.render({
                elem: '#oaEmergencyContact'
                , url: getRootPath() + 'oaEmergencyContact/selectAlls?entryId=' + pkEntry.val()
                , headers: {token: token}
                , title: '紧急联络人'
                , parseData: function (res) {
                    if (res.code === 500) {
                        return false
                    }
                    return {
                        "code": res.data.code,
                        "msg": res.data.msg,
                        "count": res.data.count,
                        "data": res.data.data
                    };
                }
                , cols: [[
                    {type: 'numbers', title: '序列', fixed: 'left'}
                    , {field: 'emergencyContactName', title: '姓名'}
                    , {field: 'relation', title: '关系'}
                    , {field: 'emergencyContactAddress', title: '联系地址'}
                    , {field: 'emergencyContactPostcode', title: '联系邮编'}
                    , {field: 'emergencyContactPhone', title: '电话'}
                ]]
            });

            //监听起草提交
            form.on('submit(demo1)', function (data) {
                console.info(data.field);
                const res = postAjax(getRootPath() + "OaEntryAlterationFlowAction/staffingPass", data.field);
                if (res.code === 1) {
                    layer.msg('新增成功3秒后关闭当前窗口', {icon: 1});
                    setTimeout(function () {
                        formClose();
                    }, 3000);
                    setTimeout(function () {
                        parent.layui.table.reload('test');//刷新父页面
                        //window.parent.location.reload();//刷新父页面
                        const index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                        parent.layer.close(index);
                    }, 3000);
                    //window.location.reload();//刷新页面
                } else if (res.code === 500) {
                    error('500');
                } else {
                    layer.msg("新增失败");
                }
                return false;
            });

        //监听审核提交不通过
        $('#demo2').on('click', function () {
            //prompt层
            layer.prompt({
                formType: 2,
                value: '',
                title: '请输入原因',
                area: ['300px', '100px']
            }, function (text, index) {
                layer.close(index);
                let datas = {
                    formReason: text,
                    pkEntryAlterationId: $("#pkEntryAlterationId").val()
                };
                /*layer.msg('您最后写下了：'+text);*/
                const res = postAjax(getRootPath() + "OaEntryAlterationFlowAction/staffingNoPass", datas);
                if (res.code === 1) {
                    layer.msg('提交成功3秒后关闭当前窗口', {icon: 1});
                    setTimeout(function () {
                        formClose();
                    },3000);
                    setTimeout(function () {
                        parent.layui.table.reload('test');//刷新父页面
                        //window.parent.location.reload();//刷新父页面
                        const index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                        parent.layer.close(index);
                    },3001);
                } else if (res.code === 500) {
                    error('500');
                } else {
                    layer.msg("新增失败");
                }
            });

            return false;
        });


            const ress = getAjaxById(getRootPath() + "OaFlowAction/selectFlowSchedule/" + pkEntryAlterationId);
            $("#schedule").html("");
            $.each(ress, function (index, item) {
                if (item.createdBy) {
                    $("#schedule").append('<li class="layui-timeline-item">\n' +
                        '        <i class="layui-icon layui-timeline-axis"></i>\n' +
                        '        <div class="layui-timeline-content layui-text">\n' +
                        '            <h3 class="layui-timeline-title">' + dateFormat('yyyy-MM-dd hh:mm:ss', new Date(item.createdTime)) + '&nbsp;&nbsp;&nbsp;' + item.flowName + '</h3>\n' +
                        '            <p>' + item.formReason + '</p>\n' +
                        '            <p>操作人：' + item.createdBy + '</p>\n' +
                        '        </div>\n' +
                        '    </li>')

                } else {
                    $("#schedule").append('<li class="layui-timeline-item">\n' +
                        '        <i class="layui-icon layui-timeline-axis"></i>\n' +
                        '        <div class="layui-timeline-content layui-text">\n' +
                        '            <h3 class="layui-timeline-title">' + dateFormat('yyyy-MM-dd hh:mm:ss', new Date(item.createdTime)) + '&nbsp;&nbsp;&nbsp;' + item.flowName + '</h3>\n' +
                        '            <p>' + item.formReason + '</p>\n' +
                        '        </div>\n' +
                        '    </li>')
                }
            });

        $("#bodys").show();
        form.render();
    });

</script>
</body>
</html>